package com.example.demo.utils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by yangge on 2017/6/25 0025.
 */
public class KKSCodeSplit {
    public static ArrayList<ArrayList<String>> kksCodeSplitFuction(ArrayList<String> oldKKSCodeList,int pieceLength){
        ArrayList<ArrayList<String>> newKKSCodeList=new ArrayList<>();
        int oldLength=oldKKSCodeList.size();
        if(oldLength<pieceLength){
            newKKSCodeList.add(oldKKSCodeList);
        }else{
            int piece=oldLength/pieceLength;
            int residue=oldLength%pieceLength;
            for(int i=0;i<piece;i++){
                ArrayList<String> pieceList=new ArrayList<>();
                pieceList.addAll(oldKKSCodeList.subList(i*pieceLength,(i+1)*pieceLength-1));
                newKKSCodeList.add(pieceList);
            }
            ArrayList<String> lastPieceList=new ArrayList<>();
            lastPieceList.addAll(oldKKSCodeList.subList(piece*pieceLength,piece*pieceLength+residue));
            newKKSCodeList.add(lastPieceList);
        }
        return newKKSCodeList;
    }
}
